package com.youku.controls
{
   import com.youku.plugins.menu.ContextMenuFacade;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import com.youku.events.PluginEvent;
   import com.youku.events.PlayerControlEvent;
   import flash.ui.ContextMenu;
   
   public class ContextMenuController extends BasePluginController
   {
      
      public function ContextMenuController() {
         super();
         this.init();
      }
      
      private var _contextMenuFacade:ContextMenuFacade;
      
      override protected function init() : void {
         this._contextMenuFacade = ContextMenuFacade.getInstance();
         this._contextMenuFacade.init(viewManager,playerProxy);
         GlobalService.addService(GlobalServiceKeys.CONTEXT_MENU_FACADE,this._contextMenuFacade);
         playerProxy.addEventListener(PluginEvent.CM_MENU_UPDATED,this.onContextMenuUpdated);
         playerProxy.addEventListener(PluginEvent.CM_STOP_PLAY,this.onContextMenuStopPlay);
         playerProxy.addEventListener(PluginEvent.CM_VIDEO_INFO,this.onContextMenuVideoInfo);
         playerProxy.addEventListener(PluginEvent.CM_GPU_OPEN,this.onContextMenuGpuOpen);
         playerProxy.addEventListener(PluginEvent.CM_GPU_CLOSE,this.onContextMenuGpuClose);
      }
      
      private function onContextMenuGpuOpen(param1:PluginEvent) : void {
         externalInterfaceProxy.onPlayerStageVideo(true);
      }
      
      private function onContextMenuGpuClose(param1:PluginEvent) : void {
         externalInterfaceProxy.onPlayerStageVideo(false);
      }
      
      private function onContextMenuVideoInfo(param1:PluginEvent) : void {
         playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.VIDEO_INFO_SHOW));
      }
      
      private function onContextMenuStopPlay(param1:PluginEvent) : void {
         facadeManager.stopVideo();
         var _loc2_:String = playerProxy.playerData.videoIdEncode;
         facadeManager.playNewVideoAndStop(_loc2_);
      }
      
      private function onContextMenuUpdated(param1:PluginEvent) : void {
         var _loc2_:ContextMenu = param1.data.menu;
         if(_loc2_ == null)
         {
            return;
         }
         playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CM_MENU_UPDATED,{"menu":_loc2_}));
      }
   }
}
